package com.yuanjin.adapter;

import java.util.Vector;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuanjin.R;
import com.yuanjin.models.FriendsShowItem;

public class FriendsShowAdapter extends BaseAdapter {
	private Vector<FriendsShowItem> list = null;
	private Context context = null;
	private LayoutInflater inflater = null;

	public FriendsShowAdapter(Vector<FriendsShowItem> list, Context context) {
		this.list = list;
		this.context = context;
		inflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null) {
			// 如果是接收，则加载左会话框模式，然后需要在前面定义一个layout进行接收
			convertView = inflater.inflate(R.layout.friendsshowitem, null);
			if (position == 0) {
				convertView.findViewById(R.id.friendshowitem_head)
						.setVisibility(View.VISIBLE);
			} else {
				convertView.findViewById(R.id.friendshow_item).setVisibility(
						View.VISIBLE);
			}
			vh = new ViewHolder();
			vh.ll_friendshow_head = (LinearLayout) convertView
					.findViewById(R.id.friendshowitem_head);
			vh.ll_friendshow_item = (LinearLayout) convertView
					.findViewById(R.id.friendshow_item);
			vh.tv_name = (TextView) convertView
					.findViewById(R.id.tv_friendshowname);

			vh.tv_message = (TextView) convertView
					.findViewById(R.id.tv_friendshowmessage);

			// vh.tv_name.setOnClickListener(new OnClickListener() {
			//
			// @Override
			// public void onClick(View v) {
			// // TODO Auto-generated method stub
			// Log.e("testing", "-------------->tv_name");
			//
			// // AsyncImageTask task = new AsyncImageTask(context);
			// //
			// task.execute("http://zhan414-domainzhan.stor.sinaapp.com/252330399E78DB96D504C96C922E9AE84A0B33F84.jpg");
			// }
			// });
			convertView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Log.e("testing", "-------------->convertView");
				}
			});
			// converview与vh建立对应关系
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}

		if (position == 0) {
			vh.ll_friendshow_head.setVisibility(View.VISIBLE);
			vh.ll_friendshow_item.setVisibility(View.GONE);
		} else {
			vh.ll_friendshow_head.setVisibility(View.GONE);
			vh.ll_friendshow_item.setVisibility(View.VISIBLE);
			// vh.tv_name.setText(position + "号朋友");
		}
		if (position == 1) {// 去掉上横线

		}

		vh.tv_name.setText(list.get(position).getFriendname());
		vh.tv_message.setText(list.get(position).getMessage());
		return convertView;
	}

	class ViewHolder {
		LinearLayout ll_friendshow_head;
		LinearLayout ll_friendshow_item;
		ImageView iv_headicon;
		TextView tv_name;
		TextView tv_message;
		ImageView iv_show;

	}
}
